package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"go-zero-demo/app/datacenter/cron/internal/config"
	"go-zero-demo/pkg/gorm/clickhouse"
	"go-zero-demo/pkg/gorm/mysql"
	"go-zero-demo/pkg/rabbitmq"
	"gorm.io/gorm"
)

type ServiceContext struct {
	Config     config.Config
	Redis      *redis.Redis
	MySQL      *gorm.DB
	ClickHouse *gorm.DB
	RabbitMq   *rabbitmq.Rabbitmq
}

func NewServiceContext(c config.Config) *ServiceContext {
	mysqlClient, err := mysql.New(c.MySQL)
	if err != nil {
		panic(err)
	}
	clickHouse, err := clickhouse.New(c.ClickHouse)
	if err != nil {
		panic(err)
	}


	rabbitMQClient, err := rabbitmq.New(c.RabbitMq)
	if err != nil {
		panic(err)
	}

	return &ServiceContext{
		Config:   c,
		Redis:    redis.MustNewRedis(c.Redis),
		MySQL:    mysqlClient,
		RabbitMq: rabbitMQClient,
		ClickHouse: clickHouse,
	}
}
